package tld.test.interpreter
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import tld.test.interpreter.runtime.Runtime;
	
	public class RuntimeTest extends Sprite
	{
		private static const _program0:String =
		<![CDATA[
			;; This is a test program.
			;; If executed it should print 42
			(print
			 (round (/ (| 7 (* (<< 1 1) 3)) 
			  (/ 1 (min (& (- (expt 2 3) 1) 6) 100.234)))))
			;; Should print some gibberish text
			(print "foo" "bar" "\x96\r\tmoar bar")
			;; Let's see how lazy evaluation works
			(if (< 100 20) (print "100 < 20")
			 (print "100 >= 20"))
			]]>.toString();
		
		public function RuntimeTest()
		{
			super();
			if (super.stage) this.init();
			else super.addEventListener(
				Event.ADDED_TO_STAGE, this.init);
		}
		
		private function init(event:Event = null):void
		{
			super.removeEventListener(Event.ADDED_TO_STAGE, this.init);
			var runtime:Runtime = new Runtime();
			runtime.run(_program0);
		}
	}
}